﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Forget.Data;

namespace Forget.HRBLL.Model
{
    public partial class Limit
    {
        private static readonly string ADDLIMIT = "HR_AddLimit";
        private static readonly string EDITLIMIT = "";
        private static readonly string DELLIMIT = "";

        #region properties
        [DataParam(20, System.Data.SqlDbType.NVarChar)]
        public string EnID { get; set; }

        [DataParam(10, System.Data.SqlDbType.NVarChar)]
        public string LimitName { get; set; }        

        [DataParam(1, System.Data.SqlDbType.Bit)]
        public bool? Used { get; set; }
        #endregion

        public static bool AddLimit(Limit limit)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(limit);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, ADDLIMIT, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.AddLimit", ex.Message, ex.StackTrace);
            }
            return false;
        }

        public static bool EditLimit(Limit limit)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(limit);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, EDITLIMIT, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.EditLimit", ex.Message, ex.StackTrace);
            }
            return false;
        }

        public static bool DelLimit(Limit limit)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(limit);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, DELLIMIT, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.DelLimit", ex.Message, ex.StackTrace);
            }
            return false;
        }
    }
}
